package cn.kailangtu.dataspot.data;

import java.util.ArrayList;
import java.util.List;

import cn.kailangtu.commonevents.data.DataBean;

public class ControlTreeNode {

    private Integer writeValue = null;

    /**
     * 操作项，用于日志记录，
     */
    private String optionTitle="";

    /***
     * 输入时是否带入旧值
     */
    private boolean taskOldValue = true;

    /**
     * 需要点击，配置值
     */
    private boolean entryToClick = false;

    /**
     * 处理方式
     * 0,常规写入
     * 2，扩大10倍写入
     * 3，处理IP等配置,这类配置键盘可输入多个点
     * 4，处理密码值等
     * 5，直接点击该控件
     * 6，写入APPSPUtils配置文件
     */
    private int processType = 0;

    /**
     * 地址
     */
    private int address = -1;
    /**
     * 范围，最小值
     */
    private float minValue = Float.MIN_VALUE;
    /**
     * 范围，最大值
     */
    private float maxValue = Float.MAX_VALUE;
    /**
     * 无规则节点，为true时，minValue,与maxValue，及是否数字不作判断
     */
    private boolean isNorule = false;
    /**
     * 需要点击节点，为true时，当该节点切换到下一节点时，会被点击一下，比如从主菜单到子菜单
     */
    private boolean needClick;
    /**
     * 等级，0为数根，每棵树只有一个根，每往下一级，加1
     */
    private int level;
    /**
     * 子树节点
     */
    private List<ControlTreeNode> children;
    /**
     * 父树节点，树根无父节点，算最高级
     */
    private ControlTreeNode parent;
    /**
     * 左项树节点
     */
    private ControlTreeNode left;
    /**
     * 左项树节点
     */
    private ControlTreeNode right;
    /**
     * 索引值，可以用控件的ID值，用于界面的控件使用
     */
    private int index;
    /**
     * 目标控件的ID,设置值，获取值用
     */
    private int targetControlId;

    /**
     * 选择项，该项不为空，调用键盘时，会出现选择键盘
     */
    private List<DataBean<Integer>> selection;


    public ControlTreeNode(){
        needClick = false;
    }

    public ControlTreeNode(int level)
    {
        this.level = level;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,int address,String optionTitle,boolean entryToClick,int writeValue)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.address = address;
        this.optionTitle = optionTitle;
        this.entryToClick = entryToClick;
        this.writeValue = writeValue;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection,int processType)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
        this.processType = processType;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection,int processType,boolean norule)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
        this.processType = processType;
        this.isNorule = norule;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection,int processType,int address,String optionTitle )
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
        this.processType = processType;
        this.address = address;
        this.optionTitle = optionTitle;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection,int processType,int address,String optionTitle, float minValue,float maxValue )
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
        this.processType = processType;
        this.address = address;
        this.optionTitle = optionTitle;
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    public ControlTreeNode(int level,int labelViewId,int targetViewId,ControlTreeNode parentNode,List<DataBean<Integer>> selection,int processType,int address,String optionTitle, float minValue,float maxValue ,boolean norule)
    {
        this.level = level;
        this.index = labelViewId;
        this.targetControlId = targetViewId;
        this.parent = parentNode;
        this.selection = selection;
        this.processType = processType;
        this.address = address;
        this.optionTitle = optionTitle;
        this.minValue = minValue;
        this.maxValue = maxValue;
        this.isNorule = norule;
    }



    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public List<ControlTreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<ControlTreeNode> children) {
        this.children = children;
    }

    public ControlTreeNode getParent() {
        return parent;
    }

    public void setParent(ControlTreeNode parent) {
        this.parent = parent;
    }

    public ControlTreeNode getLeft() {
        return left;
    }

    public void setLeft(ControlTreeNode left) {
        this.left = left;
    }

    public ControlTreeNode getRight() {
        return right;
    }

    public void setRight(ControlTreeNode right) {
        this.right = right;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public boolean isNeedClick() {
        return needClick;
    }

    public void setNeedClick(boolean needClick) {
        this.needClick = needClick;
    }

    public void addChild(ControlTreeNode node)
    {
        if(children == null)
        {
            children = new ArrayList<>();
        }
        children.add(node);
    }

    public boolean hasChild()
    {
        if(children != null && children.size()>0)
        {
            return true;
        }
        return false;
    }

    public boolean isRealNode()
    {
        return level > 0;
    }

    public int getTargetControlId() {
        return targetControlId;
    }

    public void setTargetControlId(int targetControlId) {
        this.targetControlId = targetControlId;
    }

    public List<DataBean<Integer>> getSelection() {
        return selection;
    }

    public void setSelection(List<DataBean<Integer>> selection) {
        this.selection = selection;
    }

    public void setValueRange(float minValue,float maxValue){
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    public float getMinValue() {
        return minValue;
    }

    public float getMaxValue() {
        return maxValue;
    }

    public boolean isNorule() {
        return isNorule;
    }

    public void setNorule(boolean norule) {
        isNorule = norule;
    }

    public int getAddress() {
        return address;
    }

    public void setAddress(int address,String optionTitle) {
        this.address = address;
        this.optionTitle = optionTitle;
    }

    public void sendDataToMachine()
    {

    }

    /***
     * 写给机器
     * @param content
     */
    public void setNewValue(String content)
    {
        if(processType == 0)
        {
            //默认，作为数值直接使用
            int newValue =  Integer.parseInt(content);
        }
        else if(processType == 1){
            //选择项，需要匹配选择项

        }
        else if(processType == 2)
        {
            //显示值比存值小10倍的

        }
    }

    public int getProcessType() {
        return processType;
    }

    public void setProcessType(int processType) {
        this.processType = processType;
    }


    public Integer getWriteValue() {
        return writeValue;
    }

    public void setWriteValue(Integer writeValue) {
        this.writeValue = writeValue;
    }

    public boolean isEntryToClick() {
        return entryToClick;
    }

    public void setEntryToClick(boolean entryToClick) {
        this.entryToClick = entryToClick;
    }

    public boolean isTaskOldValue() {
        return taskOldValue;
    }

    public void setTaskOldValue(boolean taskOldValue) {
        this.taskOldValue = taskOldValue;
    }

    public String getOptionTitle() {
        return optionTitle;
    }

    public void setOptionTitle(String optionTitle) {
        this.optionTitle = optionTitle;
    }
}
